
  <template >
  <div v-if="tableData.length">
    <div @click="checkItem(item, index)" v-for="(item, index) in tableData" :key="item.id" :class="dataIndex === index ? 'select' : ''" class="tent_left">
      <div class="left_one">
        <div>
          <span style="font-weight: 700" class="over_name">{{
            item.module
          }}</span>
        </div>
        <div>
          <div class="text_store" :class="getCurrent(item.status).typeBut">
            {{ getTitle(item.status) }}
          </div>
        </div>
      </div>
      <div class="tent_tent">
        <p>模板名称：{{ item.name }}</p>
        <p>发起时间：{{ item.ctime }}</p>
        <p v-if="item.teamId">班组：{{ item.teamName }}</p>
      </div>
      <div class="tent_foot">
        <div>
          <span>发起人：{{ item.cuser }}</span>
        </div>
        <div>{{ todo_time(item.ctime) }}</div>
      </div>
    </div>
  </div>
  <div v-else>
    <div style="text-align: center; margin: 100px 0 20px">
      <img style="width: 80%" src="@/assets/images/helpKong.png" alt="" />
    </div>
  </div>
</template>

<script>
export default {
  name: "auditList",
  props: {
    dataIndex: {
      type: Number | null | undefined,
      default: null,
    },
    tableData: {
      type: Array,
      default: () => [],
    },
  },
  computed: {
    getCurrent() {
      return (type) => {
        if (type == 1 || type == 2 || type == 4) {
          return {
            typeBut: "typeBut1",
            icon: "el-icon-more",
            color: { color: " #496dff" },
            bgc: { "background-color": "#5a8bff" },
          };
        } else if (type == 3) {
          return {
            typeBut: "typeBut2",
            icon: "el-icon-check",
            color: { color: " #39ce78" },
            bgc: { "background-color": "#39ce78" },
          };
        } else if (type == 5 || type == 6 || type == 7 || type == 8) {
          return {
            typeBut: "typeBut3",
            icon: "el-icon-close",
            color: { color: " #fe5a57" },
            bgc: { "background-color": "#fe5a57" },
          };
        } else {
          return {};
        }
      };
    },
    // 审批状态文字
    getTitle() {
      return (type) => {
        if (type == 0) {
          return "";
        } else if (type == 2) {
          return "待审批";
        } else if (type == 3) {
          return "已完成";
        } else if (type == 6) {
          return "已驳回";
        } else if (type == 7) {
          return "已撤销";
        }
      };
    },
  },
  methods: {
    todo_time(time) {
      if (!time) {
        return "";
      }
      var oDate = new Date();
      var newHaoMiao1 = oDate.getTime(); //当前时间,含有时分秒
      oDate.setHours(0);
      oDate.setMinutes(0);
      oDate.setSeconds(0);
      oDate.setMilliseconds(0);
      var newHaoMiao2 = oDate.getTime(); //当前时间,不含有时分秒
      var newTime = time.replace(new RegExp("-", "gm"), "/");
      var arrTime = time.substring(0, 11).replace(new RegExp("-", "gm"), "/"); //截取时间，不含有时分秒
      var showTime = time.substring(0, 11);
      var oldHaoMiao1 = new Date(newTime).getTime(); //含有时分秒的转化成毫秒
      var oldHaoMiao2 = new Date(arrTime).getTime(); //不含有时分秒的转化成毫秒
      var d1 = (newHaoMiao1 - oldHaoMiao1) / 1000;
      var d2 = (newHaoMiao2 - oldHaoMiao2) / 1000;
      var d_result = "";
      if (d2 > 0) {
        //是几天前
        var d_days = parseInt(d2 / 86400);
        if (d_days === 1) {
          d_result = "昨天";
        } else if (d_days >= 2) {
          d_result = showTime;
        }
      } else {
        //是今天
        var d_hours = parseInt(d1 / 3600);
        var d_minutes = parseInt(d1 / 60);
        if (d_hours > 0) {
          d_result = d_hours + "小时前";
        } else if (d_hours <= 0 && d_minutes > 0) {
          d_result = d_minutes + "分钟前";
        } else {
          d_result = "刚刚";
        }
      }
      return d_result;
    },
    checkItem(row, index) {
      this.$emit("change", [row, index]);
    },
  },
};
</script>

<style lang='scss' scoped>
.tent_left {
  margin-bottom: 10px;
  background: #ffffff;
  box-shadow: 0px 0px 8px 0px rgba(55, 90, 228, 0.16);
  border-radius: 2px;
  margin: 10px;
  transition: 0.3s;
  cursor: pointer;
  &:hover {
    box-shadow: 0px 0px 10px 0px rgba(55, 90, 228, 0.36);
  }
  &:active {
    transform: translateY(3px);
  }
  .left_one {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 8px 10px;
    align-items: center;
    border-bottom: 1px solid #eaeaea;
  }
}
.text_store {
  width: 82px;
  height: 30px;
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.tent_tent {
  padding: 0px 10px;
  p {
    color: #565656;
    font-size: 14px;
    line-height: 20px;
  }
}
.tent_foot {
  display: flex;
  color: #565656;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  padding: 0 15px 15px;
}

.typeBut1 {
  color: #496dff;
  background: #f5f7fc;
  border: 1px solid #5a8bff;
  &:hover {
    background: #edf1fb;
  }
}
.typeBut2 {
  color: #39ce78;
  background: #f5fff9;
  border: 1px solid #39ce78;
  &:hover {
    background: #e7fbee;
  }
}
.typeBut3 {
  color: #fe5a57;
  background: #fff3f3;
  border: 1px solid #fe5a57;
  &:hover {
    background: #fbe6e6;
  }
}
.select {
  background-color: rgba(255, 255, 255, 0.95) !important;
  border: 1px solid #496dff;
}
.over_name {
  display: inline-block;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
